let baseUrl = 'http://122.224.125.236:8080';

import axios from '@/api/axios'
import qs from 'qs';
let instance = axios() //创建axios

export default {
  get (url, params, headers) {
    let options = {}
    if (params) {
      options.params = params
    }
    if (headers) {
      options.headers = headers
    }
    url=baseUrl+url;
    return instance.get(url, options)
  },
  // application/json
  post (url, params, headers) {
    let options = {}
    if (headers) {
      options.headers = headers
    }
    url=baseUrl+url;
    return instance.post(url, params, options)
  },
  // application/json form
  post2 (url, params, headers) {
    let options = {}
    if (headers) {
      options.headers = headers
    }
    url=baseUrl+url;
    return instance.post(url, qs.stringify(params, { indices: false }), options)
  },
  // application/json form
  post3 (url, urlParams, headers) {
    let options = {}
    if (headers) {
      options.headers = headers
    }
    url=baseUrl+url;
    if(urlParams){
      url=url+"?"+qs.stringify(urlParams);
    }
    return instance.post(url,null,options)
  },
  // application/json 分页
  postPage (url, urlParams,params, headers) {
    let options = {}
    if (headers) {
      options.headers = headers
    }
    url=baseUrl+url;
    if(urlParams){
      url=url+"?"+qs.stringify(urlParams);
    }
    return instance.post(url, params, options)
  },
  // application/x-www-form-urlencoded
  postX (url, params, headers) {
    let options = {
      headers:{}
    }
    if (headers) {
      options.headers = headers
    }
    options.headers["Content-Type"] = 'application/x-www-form-urlencoded'
    url=baseUrl+url;
    return instance.post(url, params, options)
  },
  // application/x-www-form-urlencoded and 分页
  postXPage (url,urlParams, params, headers) {
    let options = {
      headers:{}
    }
    if (headers) {
      options.headers = headers
    }
    options.headers["Content-Type"] = 'application/x-www-form-urlencoded'
    url=baseUrl+url;
    if(urlParams){
      url=url+"?"+qs.stringify(urlParams);
    }
    return instance.post(url, params, options)
  },
  // multipart/form-data
  postF (url, params, headers) {
    let options = {
      headers:{}
    }
    if (headers) {
      options.headers = headers
    }
    options.headers["Content-Type"] = 'multipart/form-data'
    url=baseUrl+url;
    return instance.post(url, params, options)
  },
  // multipart/form-data and 分页
  postFPage (url,urlParams, params, headers) {
    let options = {
      headers:{}
    }
    if (headers) {
      options.headers = headers
    }
    options.headers["Content-Type"] = 'multipart/form-data'
    url=baseUrl+url;
    if(urlParams){
      url=url+"?"+qs.stringify(urlParams);
    }
    return instance.post(url, params, options)
  }
}